import moduleRegist from '@/utils/moduleRegist';
import {
  module as applicationModule
} from './module';

import {
  module as roleModule
} from '@/views/admin/Role/module';

import {
  module as currentApplicationPermissionModule
} from '@/views/admin/Permission/currentApplicationPermissionModule';

const ListView = resolve => {
  require(['./ListView'], resolve);
};

const Layout = resolve => {
  require(['./Layout'], resolve);
};

const AddForm = resolve => {
  require(['./AddForm'], resolve);
};

const EditForm = resolve => {
  require(['./EditForm'], resolve);
};

export default [
  /** 配置管理路由 */
  {
    path: 'application',
    redirect: 'application/list',
    component: Layout,
    meta: {
      title: '应用',
      name: '应用',
      permission: 'auth:menu:application:list',
      componentName: 'ApplicationLayout',
      keepAlive: true,
      icon: 'ios-apps',
      show: false
    },
    beforeEnter: (to, from, next) => {
      moduleRegist(applicationModule);
      moduleRegist(currentApplicationPermissionModule);
      moduleRegist(roleModule);
      next();
    },
    children: [{
      path: 'list',
      component: ListView,
      meta: {
        title: '应用列表',
        name: '应用',
        breadcrumb: '应用列表',
        permission: 'auth:application:query',
        keepAlive: true,
        componentName: 'ApplicationListView',
        icon: 'ios-apps'
      }
    }, {
      path: 'add',
      component: AddForm,
      meta: {
        title: '添加应用',
        name: '添加应用',
        breadcrumb: '添加应用',
        permission: 'auth:application:add',
        show: false,
        keepAlive: true,
        componentName: 'ApplicationAddView',
        icon: 'ios-apps'
      }
    }, {
      path: 'edit/:id',
      component: EditForm,
      meta: {
        title: '修改应用',
        name: '修改应用',
        breadcrumb: '修改应用',
        permission: 'auth:application:edit',
        show: false,
        keepAlive: false,
        componentName: 'ApplicationEditView',
        icon: 'ios-apps'
      }
    }]
  }
];
